package com.lg.controller;

import com.lg.service.IndexProviteService;

import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
@RequestMapping("/index")
public class IndexController {

    @Value("${server.port}")
    private String serverPort;

    @Value("${spring.configName}")
    private String configName;

    @Autowired
    private IndexProviteService indexProviteService;

    @GetMapping("/index")
    public String index() {

        System.out.println("进来了");
        return "torn-demo index...";
    }

    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        String result = "Hello Nacos Discovery port:" + serverPort + "==echo:" + string + ":configName:" + configName;
        result = indexProviteService.echo(result);
        System.out.println(result);
        try {
        	int i = new Random().nextInt(2);
        	if (i == 1) {
        		// Thread.sleep(3000);
        		// throw new RuntimeException("45451");
        	}
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    }
    

}
